﻿# define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;

#include "string.h"
namespace self
{
	void test_string01()
	{
		self::string s1("hello world");
		cout << s1.c_str() << endl;

		string::iterator it = s1.begin();
		while (it != s1.end())
		{
	        //it = 'y';
			cout << *it << " ";
			it++;
		}
		cout << endl;

		string::const_iterator it2 = s1.begin();
		while(it2 != s1.end())
		{ 
			//*it2 = 'y';
			cout << *it2;
			it2++;
		}
		cout << endl;

		for (auto e : s1)
		{
			cout << e << endl;
			e++;
		}
		cout << endl;

		 self::string s2("xxxxxxx");
		for (size_t i = 0; i < s2.size(); i++)
		{
			s2[i] = 'y';
		}
		for (size_t i = 0; i < s2.size(); i++)
		{
			cout << s2[i] << ' ';
		}
		for (auto& e : s2)
		{
			cout << e << endl;
			e++;
		}
		cout << endl;
	}

	void test_string02()
	{
		self::string s3("hello world");
		cout << s3.c_str() << endl;
		
		s3.push_back('x');
		cout << s3.c_str() << endl;

		s3.push_back('y');
		cout << s3.c_str() << endl;

		s3.push_back('z');
		cout << s3.c_str() << endl;

		self::string s4("hello world");
		cout << s4.c_str() << endl;
		
		s4.append("xxxxxx");
		cout << s4.c_str() << endl;

		s4.append("yyyyyy");
		cout << s4.c_str() << endl;
	}

	void test_string03()
	{
		self::string s5("hello world");
		cout << s5.c_str() << endl;
		
		s5 += 'x';
		cout << s5.c_str() << endl;
	
		s5 += "yyyyyy";
		cout << s5.c_str() << endl;

	}

	void test_string04()
	{
		self::string s6("hello world");
		cout << s6.c_str() << endl;

		s6.insert(2, 'x');
		cout << s6.c_str() << endl;

		s6.insert(3, "yyy");
		cout << s6.c_str() << endl;
		
		s6.erase(2, 1);
		cout << s6.c_str() << endl;
		
		s6.erase(2, 3);
		cout << s6.c_str() << endl;
	}

	void test_string05()
	{
		self::string s7("hello world");
		cout << s7.c_str() << endl;

		size_t location = s7.find('h', 1);
		cout << location<< endl;

		size_t location02 = s7.find("he", 1);
		cout << location02 << endl;
	}

	void test_string06()
	{
		self::string buyer("money");
		self::string seller("goods");

		cout << "Before the swap, buyer has " << buyer.c_str();
		cout << " and seller has " << seller.c_str() << '\n';

		buyer.swap(seller);

		cout << " After the swap, buyer has " << buyer.c_str();
		cout << " and seller has " << seller.c_str() << '\n';
	}

	void test_string07()
	{
		self::string str = "We think in generalities, but we live in details.";

		string str2 = str.substr(3, 5);     // "think"

		cout << str2.c_str() << ' ' ;

	}

	void test_string08()
	{
		self::string url("https://legacy.cplusplus.com/reference/string/string/");
		size_t pos1 = url.find(':', 1);
		self::string url1 = url.substr(0, pos1 - 0);
		cout << url1.c_str() << endl << endl;

		cout << pos1 << endl;
		size_t pos2 = url.find('/', pos1 + 3);
		cout << pos2 << endl;

		self::string url2 = url.substr(pos1 + 3, pos2 - (pos1 + 3));
		cout << url2.c_str() << endl << endl;

		self::string url3 = url.substr(pos2 + 1);
		cout << url3.c_str() << endl;
	}

	void test_string09() 
	{
		self::string s1("hello world");
		cout << s1 << endl;

		cin >> s1;
		cout << s1 << endl;
	}

	void test_string10()
	{
		self::string s8("hello world");
		cout << s8.c_str() << endl;

		string s9(s8);
		cout << s9.c_str() << endl;

		string s10 = s8;
		cout << s10.c_str() << endl;


	}
}
//int main()
//{
//	 //self::test_string01();
//	//self::test_string02();
//	//self::test_string03();
//	//self::test_string04();
//	//self::test_string05();
//	//self::test_string06();
//	//self::test_string07();
//	//self::test_string08();
//	//self::test_string09();
//	//self::test_string10();
//
//
//	string s1("xyz");
//	string::iterator it = s1.begin();
//	std::cout << *it << endl;
//
//	return 0;
//}
// extract to string


//#include<iostream>
//#include<vector>
//
//int main()
//{
//	vector<int> myvector(5);
//	int* p = myvector.data();
//
//	*p = 10;
//
//	*p = 20;
//	p[2] = 100;
//	for (size_t i = 0; i < myvector.size(); ++i)
//	{
//		cout << p[i] << endl;
//
//	}
//
//	return 0;
//}

